package com.example.work_cprovider2;

import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EditActivity extends AppCompatActivity {
    private TextView munber;
    private EditText name;
    private EditText age;
    private Button result;
    private int get_id;
    private LocalBroadcastManager localBroadcastManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);
        munber = (TextView) findViewById(R.id.c_munber);
        name = (EditText)findViewById(R.id.c_name);
        age = (EditText)findViewById(R.id.c_age);
        result = (Button)findViewById(R.id.c_result);
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
        Intent intent = getIntent();
        get_id = intent.getIntExtra("id",0);
        String get_name = intent.getStringExtra("name");
        int get_age = intent.getIntExtra("age",0);
        munber.setText(String.valueOf(get_id));
        name.setText(get_name);
        age.setText(String.valueOf(get_age));
        result.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int m =Integer.parseInt( munber.getText().toString());
                String n = name.getText().toString();
                int a = Integer.parseInt(age.getText().toString());
                Uri uri = Uri.parse("content://com.example.databasetext.provider/student");
                ContentValues values = new ContentValues();
                values.put("name",n);
                values.put("age",a);
                String s = "munber ="+m;
                getContentResolver().update(uri,values,s,null);
                Intent intent = new Intent("com.example.broadcast.ADD");
                localBroadcastManager.sendBroadcast(intent);
                finish();
            }
        });
    }
}
